package org.loong.crypto.spring.boot.autoconfigure;

import org.loong.crypto.service.CryptoService;
import org.loong.crypto.service.core.provider.ProviderFactory;
import org.loong.crypto.service.software.SoftwareCryptoService;
import org.loong.crypto.service.software.factory.SoftwareProviderFactory;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CryptoConfiguration {

    /**
     * Software crypto service.
     * 
     * @param providerFactory the providerFactory
     * @return the software crypto service
     */
    @Bean
    public CryptoService cryptoService(final ObjectProvider<ProviderFactory> providerFactory) {
        return new SoftwareCryptoService(providerFactory.getIfAvailable(SoftwareProviderFactory::new));
    }

    /**
     * The type Software provider factory configuration.
     */
    @Configuration
    static class SoftwareProviderFactoryConfiguration {

        /**
         * Software provider factory.
         * 
         * @return the {@link SoftwareProviderFactory}
         */
        @Bean
        public ProviderFactory softwareProviderFactory() {
            return new SoftwareProviderFactory();
        }
    }
}
